import CronJobManager = require('cron-job-manager');

export default class CronManager{
    private timeCount:number = 0;
    // private cronSetting:Object = {
    //     '* * * * * *':'executePerSecond',
    //     '00 */5 0-21 * * *':'executePer10MinBefore22',
    //     '00 10 22 * * *':'executePer10MinAfter22',
    //     '30 00 23 * * *':'executeEvery23',
    //     '30 00 0 * * *':'executeEveryDay'
    // };
    private cronSetting:{[key:string]:string} = {
        '30 00 23 * * *':'executeEvery23'
    };

    start():void{
        let me = this;
        let cronJobManager = new CronJobManager();
        
        for(let time in me.cronSetting){
            let functionName:string = me.cronSetting[time];
            cronJobManager.add(functionName, time, function(){
                let func = eval('me.'+functionName);
                func();
            },{
                context:{
                    functionName:functionName
                }
            });
            cronJobManager.start(functionName);
        }
    }

    private executePerSecond():void{

    }
    private executePer10MinBefore22():void{

    }
    private executePer10MinAfter22():void{

    }
    private executeEvery23():void{
        console.log(new Date(), "executeEvery23");
    }
    private executeEveryDay():void{

    }
};
